package com.ruoyi.project.business.tmpuserpost.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.tmpuserpost.entity.TmpUserpost;
import com.ruoyi.project.business.tmpuserpost.request.AddTmpUserpostRequest;
import com.ruoyi.project.business.tmpuserpost.request.ListTmpUserpostRequest;
import com.ruoyi.project.business.tmpuserpost.response.TmpUserpostResponse;
import com.ruoyi.project.business.tmpuserpost.service.ITmpUserpostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 临工岗位关系Controller
 * 
 * @author ${author}
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/business/tmpuserpost")
public class TmpUserpostController extends BaseController {
    @Autowired
    private ITmpUserpostService tmpUserpostService;

    /**
     * 查询临工岗位关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:tmpuserpost:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListTmpUserpostRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<TmpUserpostResponse> list = tmpUserpostService.selectTmpUserpostList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出临工岗位关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:tmpuserpost:export')")
    @Log(title = "临工岗位关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListTmpUserpostRequest request) {
        Long tenantId = getTenantId();
        List<TmpUserpostResponse> list = tmpUserpostService.selectTmpUserpostList(request, tenantId);
        ExcelUtil<TmpUserpostResponse> util = new ExcelUtil<>(TmpUserpostResponse.class);
        return util.exportExcel(list, "tmpuserpost");
    }

    /**
     * 获取临工岗位关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:tmpuserpost:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tmpUserpostService.selectTmpUserpostById(id));
    }

    /**
     * 新增临工岗位关系
     */
    @PreAuthorize("@ss.hasPermi('business:tmpuserpost:add')")
    @Log(title = "临工岗位关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddTmpUserpostRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tmpUserpostService.insertTmpUserpost(request, operatorId, tenantId));
    }

    /**
     * 修改临工岗位关系
     */
    @PreAuthorize("@ss.hasPermi('business:tmpuserpost:edit')")
    @Log(title = "临工岗位关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TmpUserpost tmpUserpost) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tmpUserpostService.updateTmpUserpost(tmpUserpost, operatorId, tenantId));
    }

    /**
     * 删除临工岗位关系
     */
    @PreAuthorize("@ss.hasPermi('business:tmpuserpost:remove')")
    @Log(title = "临工岗位关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(tmpUserpostService.deleteTmpUserpostByIds(ids, operatorId, tenantId));
    }
}
